package freejim.icu.highschoolhealthstatuspost.controller;


import freejim.icu.highschoolhealthstatuspost.dao.DailyPost;
import freejim.icu.highschoolhealthstatuspost.dao.Info;
import freejim.icu.highschoolhealthstatuspost.dao.InfoRepository;
import freejim.icu.highschoolhealthstatuspost.service.AnalyseService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class AnalyseController {

    @Resource
    AnalyseService analyseService;

    @Resource
    InfoRepository infoRepository;

    @RequestMapping("/admin/getUnNormalTemperatureList")
    @ResponseBody
    public Object getUnNormalTemperatureList(){
        List<DailyPost>  unNormalDetailInfos = analyseService.getUnNormalTemperatureList();
        List<Map<String,Object>> results = new ArrayList<>();
        for (DailyPost tempInfo : unNormalDetailInfos){
            Map<String,Object> tempResultData = new HashMap<>();
            Info tempUserInfo = infoRepository.getById(tempInfo.getUserid());
            tempResultData.put("date",tempInfo.getDate());
            tempResultData.put("temperature",tempInfo.getTemperature());
            tempResultData.put("userid",tempInfo.getUserid());
            tempResultData.put("name",tempUserInfo.getName());
            tempResultData.put("phonenumber",tempUserInfo.getPhonenumber());
            results.add(tempResultData);
        }
        return results;
    }
    @RequestMapping("/admin/getDangerTripList")
    @ResponseBody
    public Object getDangerTripList(){
        List<DailyPost>  dangerTripList = analyseService.getDangerTripList();
        List<Map<String,Object>> results = new ArrayList<>();
        for (DailyPost tempInfo : dangerTripList){
            Map<String,Object> tempResultData = new HashMap<>();
            Info tempUserInfo = infoRepository.getById(tempInfo.getUserid());
            tempResultData.put("date",tempInfo.getDate());
            tempResultData.put("address",tempInfo.getAddress());
            tempResultData.put("userid",tempInfo.getUserid());
            tempResultData.put("name",tempUserInfo.getName());
            tempResultData.put("phonenumber",tempUserInfo.getPhonenumber());
            results.add(tempResultData);
        }
        return results;
    }
}
